(*
Package for solution and visualization of  Impulsive systems
version: Mathematica 3.0
*)


(*
 *******************************************************
	Package: ODESolve
	Author:  Janos Karsai
	Address: Dept. Medical Informatics,
			 A. Szent-Gyorgyi Med. University
	         H-6720, Szeged, Hungary.
	E-mail:  karsai@silver.szote.u-szeged.hu
 *******************************************************
*)

BeginPackage["`ODESolve`"]; 

 
ODESolve::usage =  
"ODESolve[{rsh1,rsh2,...},{y1,y2,...},{y10,y20,...},{t,t0,T},opt]
solves the ordinary differential system 
on the interval [t0,T]. NDSolve with opt options is used. The right hand
side of the system is {rsh1,rsh2,...}, the dependent 
variables are {y1,y2,...}, The function gives the solution
in the list of InterpolationFunctions with argument.";

ODESolveTab::usage = 
"ODESolveTab[{rsh1,rsh2,...},{y1,y2,...},ICTabl,{t,t0,T},opt] solves
the ordinary differential system with multiple set of initial conditions.
ICTabl is a list of initial conditions.  For the other arguments, see ODESolve.";

ProjectionTraj::usage =
"ProjectionTraj[array,indexlist]. selects the elements of indexes 
given in indexlist from every array[[i]]."


Begin["`Private`"];


(*
  eqn. solution (InterpolationFunction object)
*)


ODESolve[xdot_List,xvar_List,icond_List,
		{t_,t0_,T_},opt___]:=
Module[{},
Return[(xvar /. Map[#->#[t]&,#]& [xvar]) /.
First[NDSolve[
	Join[
	Table[
	 xvar[[i]]'[t]==
         (xdot[[i]]/. Map[#->#[t]&,#]& [xvar]),{i,1,Length[xvar]}],
	 Table[xvar[[i]][t0]==icond[[i]],{i,1,Length[xvar]}]],xvar,
	{t,t0,T},opt]
    ]
]];

(*
Solve with a table of init. conditions (table of Interpol.Funct. object)
*)

ODESolveTab[xdot_List,xvar_List,ictab_List,{t_,t0_,T_},opt___]:=
	Map[(ODESolve[xdot,xvar,#,{t,t0,T},opt])&,ictab];

(* Create projection of the solutions with the given variables *)

ProjectionTraj[Traj_,Proj_List]:=
Map[Table[#[[Proj[[i]]]],{i,1,Length[Proj]}]&,Traj];
	
End[];

EndPackage[]; 

